//
//  AdvertisingTextCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/6/12.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "AdvertisingTextCell.h"

@implementation AdvertisingTextCell{
    QXLable *labTitle;
    UIButton *btn;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        UIView *lineView=[[UIView alloc]init];
        lineView.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.contentView);
            make.height.mas_equalTo(@.7);
        }];
        
        btn=[UIButton new];
        
        btn.userInteractionEnabled = NO;
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
      
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btn.titleLabel.font = [UIFont systemFontOfSize: 13.0];
        [btn setTitleColor:DEFAULTTEXTGDARKRAYCOLOR forState:UIControlStateNormal];
        [self.contentView addSubview:btn];
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(17);
            make.right.equalTo(self.contentView).with.offset(-10);
            make.height.equalTo(self.contentView);
        }];
        [btn setTitleColor:DEFAULTTEXTGDARKRAYCOLOR forState:UIControlStateNormal];   
        
        [self.contentView addSubview:labTitle];
        [labTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(10);
            make.centerY.equalTo(self.contentView).with.offset(5);
            make.right.equalTo(self.contentView).with.offset(-10);
        }];
        
        UIView *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.equalTo(@.7);
        }];
        
        
    }
    return self;
}

- (void)setStrTitle:(NSString *)strTitle{

    _strTitle=strTitle;
    
    if ([strTitle containsString:@"【"]) {
        [btn setAttributedTitle:[NSAttributedString tg_imageTextWithTitle:strTitle] forState:UIControlStateNormal];
    } else {
        [btn setTitle:strTitle forState:UIControlStateNormal];
    }

}

- (void)setModel:(AdvertisingModel *)model{
    
    _model=model;
    
    if ([model.Title containsString:@"【"]) {
        [btn setAttributedTitle:[NSAttributedString tg_imageTextWithTitle:model.Title] forState:UIControlStateNormal];
    } else {
        [btn setTitle:model.Title forState:UIControlStateNormal];
    }
    
}



//-(void)prepareForReuse{
//    
//    [super prepareForReuse];
//    
//    [btn setTitle:nil forState:UIControlStateNormal];
//}


///滚动公告
- (void)scrollAnnouncement{
    CGRect rect=labTitle.frame;
    [UIView animateWithDuration:labTitle.text.length/3.0 animations:^{
        [labTitle setFrame:CGRectMake(-rect.size.width+55, 0, rect.size.width, rect.size.height)];
    } completion:^(BOOL finished) {
        [labTitle setFrame:CGRectMake(SCREEN_WIDTH, 0, rect.size.width, rect.size.height)];
        [self scrollAnnouncement];
    }];
}


@end
